<template>
    <el-container style="height: 100vh" class="layout-container">
        <!-- 左侧导航栏 -->
        <el-aside :width="isCollapse ? '64px' : '200px'" style="transition: all 0.4s ease-out;" class="sidebar">
            <div class="logo">🌀</div>
            <el-menu :default-active="$route.path" class="el-menu-vertical-demo" style="transition: all 0.4s ease-out;"
                :collapse="isCollapse" router>
                <el-menu-item index="/page1">
                    <el-icon>
                        <document />
                    </el-icon>
                    <span>首页</span>
                </el-menu-item>
                <!-- <el-menu-item index="/other">
                    <el-icon>
                        <folder />
                    </el-icon>
                    <span>其他页面</span>
                </el-menu-item> -->
            </el-menu>
        </el-aside>

        <!-- 主内容区域 -->
        <el-container>
            <!-- 顶部导航栏 -->
            <el-header class="header">
                <div class="left" style="display: flex;align-items: center;">
                    <el-button @click="isCollapse = !isCollapse" size="small" icon="Menu" />
                    <el-breadcrumb separator="/" style="margin-left: 20px">
                        <el-breadcrumb-item>BreezeAdmin</el-breadcrumb-item>
                        <el-breadcrumb-item>{{ breadcrumb }}</el-breadcrumb-item>
                    </el-breadcrumb>
                </div>

                <el-dropdown @command="handleCommand">
                    <span class="user">
                        <el-avatar size="small"
                            src="https://repo.df1919.net/uploads/-/system/user/avatar/28/avatar.png?width=800" />
                        <span style="margin-left: 8px;">管理员</span>
                    </span>
                    <template #dropdown>
                        <el-dropdown-menu>
                            <el-dropdown-item command="logout">退出登录</el-dropdown-item>
                        </el-dropdown-menu>
                    </template>
                </el-dropdown>
            </el-header>

            <!-- 页面内容区域 -->
            <el-main class="main-content">
                <router-view />
            </el-main>
        </el-container>
    </el-container>
</template>

<script setup>
import { ref, computed } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { Document, Folder, Menu } from '@element-plus/icons-vue'

const isCollapse = ref(false)
const router = useRouter()
const route = useRoute()

const breadcrumb = computed(() => {
    switch (route.path) {
        case '/page1': return '首页'
        case '/other': return '其他页面'
        default: return '未知页面'
    }
})

function handleCommand(command) {
    if (command === 'logout') {
        localStorage.removeItem('auth_token');
        router.push('/login')
    }
}
</script>

<style scoped>
.layout-container {
    height: 100vh;
    width: 100vw;
    /* ✅ 关键：使最外层容器铺满整个窗口 */
}

.sidebar {
    background-color: #001529;
    color: white;
}

.header {
    background-color: #fff;
    line-height: 60px;
    padding: 0 20px;
    border-bottom: 1px solid #eee;
}

.main-content {
    overflow: auto;
    background-color: #f5f7fa;
}

.sidebar {
    background-color: #001529;
    color: #fff;
}

.logo {
    height: 60px;
    text-align: center;
    line-height: 60px;
    font-size: 20px;
    color: #fff;
    font-weight: bold;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #fff;
    padding: 0 20px;
    border-bottom: 1px solid #eee;
}

.user {
    display: flex;
    align-items: center;
    cursor: pointer;
}
</style>